package com.zhangyj.impl.component.grid;

import java.util.Iterator;

import com.zhangyj.component.grid.model.ITableModel;
import com.zhangyj.impl.component.type.GridCol;

public class DefaultTableMode implements ITableModel {
	Iterator<Object[]> iterator = null;
	Object[] v = null;
	GridCol[] columnNames = null;

	public DefaultTableMode(Iterator<Object[]> iter, GridCol[] columnNames) {
		this.iterator = iter;
		this.columnNames = columnNames;
	}

	
	public Class<?> getColumnClass(int columnIndex) {
		if (v[columnIndex] == null) {
			return String.class;
		}
		return v[columnIndex].getClass();
	}

	
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return columnNames.length;
	}

	
	public String getColumnName(int columnIndex) {
		// TODO Auto-generated method stub
		return columnNames[columnIndex].caption;
	}
	
	public int getColumnWidth(int columnIndex) {
		// TODO Auto-generated method stub
		return columnNames[columnIndex].width;
	}
	
	public Object getValueAt(int columnIndex) {
		// TODO Auto-generated method stub
		return v[columnIndex];
	}

	
	public boolean next() {
		// TODO Auto-generated method stub
		if (this.iterator.hasNext()) {
			v = this.iterator.next();
			return true;
		}
		return false;
	}

}
